package com.thesis.student.controller;

import com.alibaba.fastjson.JSONObject;
import com.thesis.manage.common.utils.Result;
import com.thesis.manage.domain.Student;
import com.thesis.manage.service.StudentThesisService;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author php
 * @date 2018/3/14
 */
@RequestMapping("/student/thesis")
@RestController
public class StudentThesisController extends BaseController {

    @Resource
    private StudentThesisService studentThesisService;

    /**
     * 学生查看自己选题
     */
    @GetMapping("/info")
    public Map<String, Object> findByStudentId() {
        return buildMessage(() -> {
            Result result = getUser();
            Student student = JSONObject.parseObject(result.getData().toString(), Student.class);
            return studentThesisService.findByStudentId(student.getId());

        });
    }

    /**
     * 选题
     */
    @GetMapping("/{id}/select")
    public Map<String, Object> selectThesis(@PathVariable Long id) {
        return buildMessage(() -> {
            Result result = getUser();
            Student student = JSONObject.parseObject(result.getData().toString(), Student.class);
            studentThesisService.selectThesis(id, student.getId());
            return null;
        });
    }

    /**
     * 可选题列表
     */
    @GetMapping("/list")
    public Map<String, Object> showThesisList(Pageable pageable) {
        return buildMessage(() -> {
            Result result = getUser();
            Student student = JSONObject.parseObject(result.getData().toString(), Student.class);
            return studentThesisService.showThesisList(pageable, student.getStudentNumber(), student.getId());
        });
    }

    /**
     * 查看选题成功后的论题
     */
    @GetMapping("/my")
    public Map<String, Object> myThesis() {
        return buildMessage(() -> {
            Result result = getUser();
            Student student = JSONObject.parseObject(result.getData().toString(), Student.class);
            return studentThesisService.myThesis(student.getId());
        });
    }
}
